package com.example.feign.controller;

import com.example.feign.entity.Chapter;
import com.example.feign.feign.ChapterFeign;
import com.example.feign.util.EntityToMap;
import com.example.feign.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/chapter")
public class ChapterFeignController {
    @Autowired
    ChapterFeign chapterFeign;

    @GetMapping("/get")
    public Response getChapter(@RequestParam(value = "page",required = false) Integer page,
                              @RequestParam(value = "size",required = false) Integer size,
                              @RequestParam(value = "spId",required = true) String spId,
                              @RequestParam(value = "courseName",required = false) String courseName,
                              Chapter chapter){
        Map map = new HashMap<>();
        map = EntityToMap.object2Map(chapter);
        return chapterFeign.getChapter(page, size, spId, courseName, map);
    }

    @PostMapping("/add")
    public Response addChapter(Chapter chapter){
        return chapterFeign.addChapter(chapter);
    }

    @PutMapping("/update")
    public Response updateChapter(Chapter chapter){
        return chapterFeign.updateChapter(chapter);
    }

    @PutMapping("/del")
    public Response delChapter(@RequestParam(value = "chapterId",required = true) String chapterId){
        return chapterFeign.delChapter(chapterId);
    }
}
